package com.yike.user.controller;

import com.yike.user.entity.VoiceSettings;
import com.yike.user.param.VoiceSettingsParam;
import com.yike.user.service.VoiceSettingsService;
import com.yike.user.vo.VoiceSettingsVo;
import lombok.extern.slf4j.Slf4j;
import com.yike.user.param.VoiceSettingsPageParam;
import com.yike.common.base.BaseController;
import com.yike.common.api.ApiResult;
import com.yike.common.pagination.Paging;
import com.yike.common.api.IdParam;
import com.yike.common.log.Module;
import com.yike.common.log.OperationLog;
import com.yike.common.enums.OperationLogType;
import com.yike.common.api.Add;
import com.yike.common.api.Update;
import org.springframework.validation.annotation.Validated;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 语音设置 控制器
 *
 * @author Sakura
 * @since 2025-04-02
 */
@Slf4j
@RestController
@RequestMapping("/platform/voiceSettings")
@Module("user")
@Api(value = "语音设置API", tags = {"平台语音设置"})
public class VoiceSettingsController extends BaseController {

    @Autowired
    private VoiceSettingsService voiceSettingsService;

    /**
     * 添加语音设置
     */
    @PostMapping("/add")
    @OperationLog(name = "添加语音设置", type = OperationLogType.ADD)
    @ApiOperation(value = "添加语音设置", response = ApiResult.class)
    public ApiResult<Boolean> addVoiceSettings(@Validated(Add.class) @RequestBody VoiceSettingsParam voiceSettingsParam) throws Exception {
        boolean flag = voiceSettingsService.saveVoiceSettings(voiceSettingsParam);
        return ApiResult.result(flag);
    }

    /**
     * 修改语音设置
     */
    @PostMapping("/update")
    @OperationLog(name = "修改语音设置", type = OperationLogType.UPDATE)
    @ApiOperation(value = "修改语音设置", response = ApiResult.class)
    public ApiResult<Boolean> updateVoiceSettings(@Validated(Update.class) @RequestBody VoiceSettingsParam voiceSettingsParam) throws Exception {
        boolean flag = voiceSettingsService.updateVoiceSettings(voiceSettingsParam);
        return ApiResult.result(flag);
    }

    /**
     * 删除语音设置
     */
    @PostMapping("/delete/{id}")
    @OperationLog(name = "删除语音设置", type = OperationLogType.DELETE)
    @ApiOperation(value = "删除语音设置", response = ApiResult.class)
    public ApiResult<Boolean> deleteVoiceSettings(@PathVariable("id") Long id) throws Exception {
        boolean flag = voiceSettingsService.deleteVoiceSettings(id);
        return ApiResult.result(flag);
    }

    @PostMapping("/batchDel")
    @OperationLog(name = "批量删除语音设置", type = OperationLogType.UPDATE)
    @ApiOperation(value = "批量删除语音设置", response = ApiResult.class)
    public ApiResult<Boolean> batchDel(@Validated(Update.class) @RequestBody List<Long> ids) throws Exception {
        boolean flag = voiceSettingsService.batchDel(ids);
        return ApiResult.result(flag);
    }

    /**
     * 获取语音设置详情
     */
    @GetMapping("/info/{id}")
    @OperationLog(name = "语音设置详情", type = OperationLogType.INFO)
    @ApiOperation(value = "语音设置详情", response = VoiceSettingsVo.class)
    public ApiResult<VoiceSettingsVo> getVoiceSettings(@PathVariable("id") Long id) throws Exception {
        VoiceSettingsVo voiceSettings = voiceSettingsService.getVoiceSettings(id);
        return ApiResult.ok(voiceSettings);
    }

    /**
     * 语音设置分页列表
     */
    @PostMapping("/getPageList")
    @OperationLog(name = "语音设置分页列表", type = OperationLogType.PAGE)
    @ApiOperation(value = "语音设置分页列表", response = VoiceSettingsVo.class)
    public ApiResult<Paging<VoiceSettingsVo>> getVoiceSettingsPageList(@Validated @RequestBody VoiceSettingsPageParam voiceSettingsPageParam) throws Exception {
        Paging<VoiceSettingsVo> paging = voiceSettingsService.getVoiceSettingsPageList(voiceSettingsPageParam);
        return ApiResult.ok(paging);
    }

    @PostMapping("/sync")
    @OperationLog(name = "同步", type = OperationLogType.UPDATE)
    @ApiOperation(value = "同步", response = ApiResult.class)
    public ApiResult<Boolean> sync() throws Exception {
        boolean flag = voiceSettingsService.sync();
        return ApiResult.result(flag);
    }

}
